package business.service.exchange;

import android.os.Handler;
import android.os.Message;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;

public class BDLocationServiceListener implements BDLocationListener {
	public BDLocationServiceListener(Handler handler) {
		this.handler = handler;
	}

	public Handler getHandler() {
		return handler;
	}

	public void setHandler(Handler handler) {
		this.handler = handler;
	}

	private Handler handler = null;

	@Override
	public void onReceiveLocation(BDLocation location) {
		if (location == null)
			return;
		StringBuffer sb = new StringBuffer(256);
		
		sb.append("时间: ");
		sb.append(location.getTime());
		
//		sb.append("\nerror code : ");
//		sb.append(location.getLocType());
		
		sb.append("\n纬度: ");
		sb.append(location.getLatitude());
		sb.append("\n经度: ");
		sb.append(location.getLongitude());
		sb.append("\n误差: ");
		sb.append(location.getRadius());
		
		if (location.getLocType() == BDLocation.TypeGpsLocation) {
			sb.append("\n速度: ");
			sb.append(location.getSpeed());
		//	sb.append("\nsatellite : ");
		//	sb.append(location.getSatelliteNumber());
		} else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {
			sb.append("\n地址: ");
			sb.append(location.getAddrStr());
		}

		Message msg = new Message();
		
		//162~167： 服务端定位失败。 
		int error = location.getLocType();
		if(error >= 162 && error <= 167)
			msg.what = BDLocationService.LOCATE_FAIL;
		else
			msg.what = BDLocationService.LOCATE_SUCCESS;
		
		msg.obj = sb.toString();
		handler.sendMessage(msg);
	}

	@Override
	public void onReceivePoi(BDLocation poiLocation) {
		//暂时不用POI
		/*
		if (poiLocation == null) {
			return;
		}
		StringBuffer sb = new StringBuffer(256);
		sb.append("Poi time : ");
		sb.append(poiLocation.getTime());
		sb.append("\nerror code : ");
		sb.append(poiLocation.getLocType());
		sb.append("\nlatitude : ");
		sb.append(poiLocation.getLatitude());
		sb.append("\nlontitude : ");
		sb.append(poiLocation.getLongitude());
		sb.append("\nradius : ");
		sb.append(poiLocation.getRadius());
		if (poiLocation.getLocType() == BDLocation.TypeNetWorkLocation) {
			sb.append("\naddr : ");
			sb.append(poiLocation.getAddrStr());
		}
		if (poiLocation.hasPoi()) {
			sb.append("\nPoi:");
			sb.append(poiLocation.getPoi());
		} else {
			sb.append("noPoi information");
		}

		Log.i("Poi定位:", sb.toString());
		*/
	}

}
